﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using WMSADL.SY;
using WMSAML.SY;

namespace WMSABL.SY
{
    public class TRolePermissionRelation_BLL
    {
        TRolePermissionRelation_DAL dal = new TRolePermissionRelation_DAL();

        /// <summary>
        /// 设置角色权限
        /// </summary>
        /// <param name="roleStr"></param>
        /// <param name="rid"></param>
        /// <returns></returns>
        public bool AddTRolePermissionRelation(int rid, string roleStr)
        {
            bool falg = false;
            TRolePermissionRelation_Entity entity = new TRolePermissionRelation_Entity();
            entity.Role_id = rid;
            entity.Permission_id = roleStr;
            if (!ExistsByID(rid))
            {
                falg = Add(entity) == 0 ? false : true;
            }
            else
            {
                falg = Update(entity);
            }
            return falg;
        }
        /// <summary>
        /// 
        /// </summary>
        public int Add(TRolePermissionRelation_Entity entity)
        {
            return dal.Add(entity);
        }

        /// <summary>
        /// 删除
        /// </summary>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(TRolePermissionRelation_Entity entity)
        {
            return dal.Update(entity);
        }

        /// <summary>
        /// ByRoleId
        /// </summary>
        public bool ExistsByID(int rid)
        {
            return dal.ExistsByID(rid);
        }

        /// <summary>
        /// ByID
        /// </summary>
        /// <summary>
        public TRolePermissionRelation_Entity GetEntityByID(int id)
        {
            return dal.GetEntityByID(id);
        }
    }
}
